package com.jic.market.request;

import com.google.common.base.Joiner;
import com.jic.common.base.vo.AdminOperate;
import com.jic.common.base.vo.enums.DeptTypeEnums;
import com.jic.market.tuple.Tuple;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * description: BaseRequest
 * date: 2020/1/10 15:00
 * author: admin
 * version: 1.0
 */
@Data
@Setter
@Getter
public class BaseRequest {
    private static final long serialVersionUID = 3109559160387277161L;
    private int pageNo = 1;
    private int pageSize = 10;
    private Long creator;
    private String creatorName;
    private Long updator;
    private String updatorName;
    private List<Tuple<String, String>> orderBys;
    private int start = 1;
    private int limit = 10;

    private AdminOperate adminOperate;


    // token
    private String token;
    //----操作信息-----
    // 操作人ID
    private Long operator;
    // 操作人的用户名，登录的时候用的
    private String operateUsername;
    // 操作人的姓名
    private String operateName;
    // 操作日志
    private String operatorLog;
    //----权限信息-----
    // 组织类型
    public DeptTypeEnums deptType;
    // 所属组织ID
    public Long deptId;
    // 子平台id、商家id、店铺id、运营id 与dept_type同时使用
    public Long businessId;
    // 当前用户子平台数据权限ids
    public List<Long> childIds;
    // 当前用户商家数据权限ids
    public List<Long>  merchantIds;
    // 当前用户店铺数据权限ids
    public List<Long>  storeIds;

    public String genOrderBys(){
        if(orderBys == null || orderBys.size() == 0){
          return null;
        }
        Map<Object, Object> orderMaps = orderBys.stream().collect(Collectors.toMap(Tuple::getF, Tuple::getS, (key1, key2) -> key2));
        String join = Joiner.on(",").withKeyValueSeparator(" ").join(orderMaps);
        return join;
    }

//    public static void main(String[] args) {
//        List<Tuple<String, String>> tuples = Lists.newArrayList(new Tuple<String,String>("id","aes"),new Tuple<String,String>("age","desc"));
//        Map<Object, Object> orderMaps = tuples.stream().collect(Collectors.toMap(Tuple::getF, Tuple::getS, (key1, key2) -> key2));
//        String join = Joiner.on(",").withKeyValueSeparator(" ").join(orderMaps);
//        System.out.printf(join);
//    }
}
